package com.market.manager;

import java.util.List;

import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.market.domain.Purchase;
import com.market.domain.PurchaseDetail;

public interface PurchaseManager extends GenericManager<Purchase, Long> {
	/**
	 * This method fetch all purchase details of specific purchase
	 * 
	 * @param order
	 * @return
	 */
	@Transactional(propagation = Propagation.REQUIRED, readOnly=true)
	public List<PurchaseDetail> fetchDetails(Purchase purchase);
	
	/**
	 * This method only change the status to Confirmed and confirmedDate to current date.
	 * This means one of employee have contact supplier, and confirm every items is available.
	 * @param purchase
	 * @return
	 */
	@Transactional(propagation = Propagation.REQUIRED, rollbackFor=RuntimeException.class )
	public Purchase confirm(Purchase purchase);
	
	/**
	 * This method only change the status to Received and confirmedDate to null.
	 * This means this has confirm with supplier that every items is available.
	 * @param purchase
	 * @return
	 */
	@Transactional(propagation = Propagation.REQUIRED, rollbackFor=RuntimeException.class )
	public Purchase unConfirm(Purchase purchase);
	
	/**
	 * This method change the status to Arrived and arrivedDate to current date;
	 * This means the purchase have been transported from supplier to our warehouse.
	 * @param purchase
	 * @return
	 */
	@Transactional(propagation = Propagation.REQUIRED, rollbackFor=RuntimeException.class )
	public Purchase receive(Purchase purchase);
	
	
	/**
	 * This method change the status to Confirmed and arrivedDate to null;
	 * This means this purchase has confirmed with supplier every items is avalaible.
	 * But those thing has not transport to our warehouse.
	 * @param purchase
	 * @return
	 */
	@Transactional(propagation = Propagation.REQUIRED, rollbackFor=RuntimeException.class )
	public Purchase unReceive(Purchase purchase);
	
	/**
	 * This method change the status to processed and processedDate to current date;
	 * This means all items of the purchase have been processed, ready to be prepared
	 * for customer's order,plus to inventory
	 * 
	 * @param purchase
	 * @return
	 */	
	@Transactional(propagation = Propagation.REQUIRED, rollbackFor=RuntimeException.class )
	public Purchase process(Purchase purchase);
	
	
	/**
	 * This method change the status to Received and processedDate to null;
	 * This means all items of the purchase have been received, but have processed, that means is
	 * not ready to be prepared to customer's order.
	 * This operation minus from inventory.
	 * 
	 * @param purchase
	 * @return
	 */	
	@Transactional(propagation = Propagation.REQUIRED, rollbackFor=RuntimeException.class )
	public Purchase unProcess(Purchase purchase);
	
	
	/**
	 * This method change the status to Paid and paidDate to current date.
	 * And update supplier's balance
	 * @param purchase
	 * @return
	 */
	@Transactional(propagation = Propagation.REQUIRED, rollbackFor=RuntimeException.class )
	public Purchase pay(Purchase purchase);
	
	/**
	 * This method change the status to Canceled and canceledDate to current date.
	 * Only purchase status is Purchased and Confirmed can be canceled.
	 * After the purchase Arrived, this purchase can not be canceled.
	 * @param purchase
	 * @return
	 */
	@Transactional(propagation = Propagation.REQUIRED, rollbackFor=RuntimeException.class )
	public Purchase cancel(Purchase purchase);
	
	
	
	
}